#ifndef _CACHE_H_
#define _CACHE_H_
#include <concurrency/Mutex.h>
#include <concurrency/Thread.h>
#include <map>
#include <list>
#include "md5.h"

using namespace std;
using namespace facebook::thrift::concurrency;

template <typename K,typename V>
class Cache{
	public:
		Cache(int maxSize=100000);
		void SetMaxSize(int maxSize);
		bool Get(const  K &,V & );
	    int Put(const  K & ,const V &);
		int Clear();
		void Hit(const K &);
	protected:
	    ReadWriteMutex m_rwmutexData;
		map<K, V> m_mapData;
		list<K> m_listLRU;
		unsigned int m_maxSize;
		map< K,typename list<K>::iterator>  m_mapLRU;
	    Mutex m_mutexLRU;
};
template <typename V>
class MD5Cache:public Cache<ycache::MD5_DATA,V>{
public:
	MD5Cache(int size);
	bool Get(const string &,V & );
	int Put(const  string  & ,const V &);
	int Put(const ycache::MD5_DATA  & ,const V &);
};
#endif
